﻿using PaperMaster.Chess.Bell;
using PaperMaster.Chess.CardSpace;
using PaperMaster.Chess.Enemy;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace PaperMaster.Chess
{
    /// <summary>
    /// 本类用于结合监听敌人动向、玩家发牌、棋子行动等等综合的战斗相关类，并调用它们。
    /// 本类接受用户输入、网络发来的Command，并调用相关事件。
    /// </summary>
    public class FightController
    {
        bool _onLine = false;

        public FightController()
        {
            GetComponents();
            RegisterEvents();
        }
        ~FightController()
        {
            UnregisterEvents();
        }
        /// <summary>
        /// 获取各模块
        /// </summary>
        void GetComponents()
        {

        }
        /// <summary>
        /// 注册事件
        /// </summary>
        void RegisterEvents()
        {
            FightBeginEvent.Register(OnFightBegin);
            FightEndEvent.Register(OnFightEnd);
            PlayerTurnBeginEvent.Register(OnPlayerTurnStart);
            PlayerTurnEndEvent.Register(OnPlayerTurnEnd);
        }
        void UnregisterEvents()
        {
            FightBeginEvent.Unregister(OnFightBegin);
            FightEndEvent.Unregister(OnFightEnd);
            PlayerTurnBeginEvent.Unregister(OnPlayerTurnStart);
            PlayerTurnEndEvent.Unregister(OnPlayerTurnEnd);
        }
        /// <summary>
        /// 每帧调用该函数。
        /// </summary>
        public void FrameFun()
        {
            GetInput();
            if (_onLine)
            {
                ListenServer();
            }
        }
        /// <summary>
        /// 获取用户输入，并触发相关事件
        /// </summary>
        void GetInput()
        {

        }
        /// <summary>
        /// 监听网络
        /// </summary>
        void ListenServer()
        {

        }
        #region 事件响应函数
        ChessBoardController _boardController;
        BellController _bellController;
        PileController _pileController;
        EnemyController _enemyController;
        /// <summary>
        /// 该函数应负责获取敌人、生成抽弃牌堆、向铃声、地形几个Controller传初始化命令等等职责
        /// </summary>
        void OnFightBegin()
        {
            _boardController = ChessBoardViewController.GetController();
            _bellController = BellViewController.GetController();
            _pileController = PileViewController.GetController();
            _enemyController = EnemyViewController.GetController();

            _boardController.FightBeginExecute();
            _bellController.FightBeginExecute();
            _pileController.FightBeginExecute();
            _enemyController.FightBeginExecute();
        }
        /// <summary>
        /// 该函数负责根据战斗结果结束副本或游戏，计算奖励、命令铃、战斗场景离开等等工作
        /// </summary>
        void OnFightEnd()
        {
            _boardController.FightEndExecute();
            _bellController.FightEndExecute();
            _pileController.FightEndExecute();
            _enemyController.FightEndExecute();
        }
        /// <summary>
        /// 该函数负责触发一些回合开始时产生的全局效果，这不包括默认的从抽牌堆抽牌
        /// </summary>
        void OnPlayerTurnStart()
        {

        }
        /// <summary>
        /// 该函数负责向棋盘下开始棋子攻击指令，这不包括默认向抽牌堆弃牌
        /// </summary>
        void OnPlayerTurnEnd()
        {
        }
        #endregion
    }
}
